import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { MessageService } from 'primeng/api/public_api';
import { MyCookie } from '../utils/my-cookie';
import { PathParam } from "../config/pathParam";
import { Observable } from 'rxjs';


@Injectable({
  providedIn: 'root'
})
export class UserService {

    private userURL:string = PathParam.base_url + 'api/user';
    
    constructor(private http: HttpClient) { }

    public UserRegister(username:string, paaaword:string, nickname:string){
        let jsonObj = {"username":username, "password":paaaword, "nickname":nickname};
        return this.http.post(this.userURL+'/register', jsonObj, {responseType: 'text'});
    }

    public UserLogin(username:string, password:string): Observable<any>{
        return this.http.post(this.userURL + "/login", {username:username, password:password});
    }
    
    //count: 得到最活跃的前 $count 个用户，如果count=-1，返回全部用户。
    public getActiveUsers(count:number): Observable<any>{
      return this.http.get(this.userURL+"/info/" + count);
    }

}
